package com.portal.common.thread.example.part1;

/**
 * 方式二：实现Runnable接口
 * 优点：
 * 1、适合多个相同的程序代码线程共享资源
 * 2、避免单继承
 */
class MyThread2 implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("新开线程运行  :  " + i);
        }
    }
}
public class Demo2 {
    public static void main(String[] args) {
        MyThread2 myThread2 = new MyThread2();
        Thread thread = new Thread(myThread2);
        thread.start();
        for (int i = 0; i < 10; i++) {
            System.out.println("主线程运行  :  " + i);
        }
    }
}
